package com.tma.internship.ClassesInfo;

import java.util.List;

import com.tma.internship.activities.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
	private Context mContext;
	private int resID;
	private List<Bitmap> bm;
	private List<FileInfo> fInfos;
    public ImageAdapter(Context c,List<Bitmap> bm,int resID,List<FileInfo> fInfos) {
        mContext = c;
        this.bm = bm;
        this.fInfos = fInfos;
        this.resID = resID;
    }
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return fInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub 
		return fInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView imageView;
		View v = convertView;
        if (v == null) {  // if it's not recycled, initialize some attributes
        	LayoutInflater mInflater = LayoutInflater.from(mContext);
			v = mInflater.inflate(resID, null);
        	
			v.setLayoutParams(new GridView.LayoutParams(150, 300));
			v.setPadding(8, 8, 8, 8);
        }
        imageView = (ImageView) v.findViewById(R.id.imgviewgr);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        
        imageView.setImageBitmap(bm.get(position));
        TextView nameTxt = (TextView) v.findViewById(R.id.nameviewgr);
        TextView sizeTxt = (TextView) v.findViewById(R.id.sizeviewgr);
        TextView pageTxt = (TextView) v.findViewById(R.id.pageviewgr);
        FileInfo fInfo = fInfos.get(position);
        nameTxt.setText(mContext.getString(R.string.ebook)+fInfo.getName());
        sizeTxt.setText(mContext.getString(R.string.size)+fInfo.getSize());
        pageTxt.setText(mContext.getString(R.string.page)+fInfo.getNumOfPage());
        return v;

	}

}
